package model.macro
{
	import flash.geom.Point;
	
	/**
	 * A territory is a location on the map. The territory contains a fortress
	 * and can contain units and buildings. A territory either is neutral or
	 * belongs to a player. When it belongs to a player, it gives that player
	 * a certain amount of money at the beginning of their turn.
	 */
	public class Territory
	{
		/**Name of the territory.*/
		public var name:String;
		
		/**List of adjacent territories.**/
		public var adjacent_territories:Vector.<Territory>;
		
		/**Reference to the player who owns this land*/
		public var owner:Player;
		
		/**List of units in this territory.*/
		public var units:Vector.<Unit>;
		
		/**The fortress in this territory*/
		public var fortress:Fortress
		
		/**Buildings this territory contains.*/
		public var buildings:Vector.<Building>;
		
		/**Amount of money per turn*/
		public var income:int;
		
		/**Coordinate postion*/
		public var location:Point;
		
		/**
		 * Create a new territory
		 */
		public function Territory(name:String)
		{
			this.name = name;
			owner = Player.NEUTRAL;
			adjacent_territories = new Vector.<Territory>();
			units = new Vector.<Unit>();
			buildings = new Vector.<Building>();
			addBuilding(Building.CITY_CENTER);
			fortress = new Fortress(FortressType.OUTPOST);
		}
		
		/**
		 * @param	building
		 */
		public function addBuilding(building:Building):void
		{
			buildings.push(building);
		}
		
		public function isAdjacent(otherTerritory:Territory):Boolean
		{
			return (otherTerritory.adjacent_territories.indexOf(this) >= 0);
		}
		
		public function toString():String
		{
			return "<Territory: Owner: " + owner + ">";
		}
	}

}